package com.deram.ctin.serv.member.service.impl;

import com.deram.ctin.common.utils.BusinessUtils;
import com.deram.ctin.common.utils.ValidateUtils;
import com.deram.ctin.serv.member.entity.MemberFeedback;
import com.deram.ctin.serv.member.entity.MemberInfo;
import com.deram.ctin.serv.member.mapper.MemberInfoMapper;
import com.deram.ctin.serv.member.service.MemberInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @Author: jtt
 * @Description:
 * @Date: 2017/9/22 9:29
 * @version: V1.0
 */
@Service
public class MemberInfoServiceImpl implements MemberInfoService {

    @Autowired
    private MemberInfoMapper memberInfoMapper;

    @Override
    public MemberInfo find(Long userId) {
        ValidateUtils.isId(userId, "用户ID");
        MemberInfo memberInfo = memberInfoMapper.selectById(userId);
        BusinessUtils.notNull(memberInfo, "用户信息不存在");
        return memberInfo;
    }

    @Override
    public MemberInfo save(MemberInfo param) {
        ValidateUtils.isId(param.getUserId(), "用户ID");
        MemberInfo memberInfo = memberInfoMapper.selectById(param.getUserId());
        if (null == memberInfo) {
            memberInfoMapper.insert(param);
        } else {
            memberInfoMapper.updateById(param);
        }
        return param;
    }
}
